<div class="selenium-notes">
<h1>Keyboard Actions in Selenium WebDriver</h1>
<p>Keyboard Actions in Selenium WebDriver are advanced keyboard interactions used to automate actions such as typing, pressing individual keys, using keyboard shortcuts, selecting text, copying and pasting content, navigating between elements, submitting forms, and interacting with applications that depend on keyboard events.</p>
<p>In Selenium Java, keyboard interactions are commonly performed using the <code>Actions</code> class together with <code>Keys</code> from <code>org.openqa.selenium.Keys</code>. Keyboard actions can be combined with mouse actions to create realistic and reusable browser automation workflows.</p>
<p><a href="https://www.justacademy.co/course-detail/selenium-training" target="_blank" rel="noopener noreferrer">Selenium Training Course</a> | <a href="https://www.justacademy.co/register-for-course-demo" target="_blank" rel="noopener noreferrer">Register for Course Demo</a></p>
<hr>
<h2>1. What are Keyboard Actions?</h2>
<p>Keyboard Actions are automated keyboard operations performed against web elements or the active browser context. Selenium can simulate key presses such as Enter, Tab, Shift, Control, Alt, Escape, Arrow keys, Function keys, and many other keyboard inputs.</p>
<pre><code>Actions actions = new Actions(driver);
actions.sendKeys(Keys.ENTER).perform();</code></pre>
<hr>
<h2>2. Why are Keyboard Actions Important?</h2>
<p>Modern web applications often depend on keyboard events for navigation, shortcuts, form submission, accessibility, menus, search boxes, and rich user interfaces.</p>
<ul>
<li>Automates keyboard-based workflows.</li>
<li>Supports keyboard shortcuts.</li>
<li>Supports form navigation.</li>
<li>Can simulate Enter, Tab, Escape and Arrow keys.</li>
<li>Supports text selection.</li>
<li>Supports copy and paste operations.</li>
<li>Can be combined with mouse actions.</li>
<li>Helps test keyboard accessibility.</li>
<li>Supports complex web application interactions.</li>
</ul>
<hr>
<h2>3. Actions Class</h2>
<p>The <code>Actions</code> class provides methods for advanced mouse and keyboard interactions. It can create sequences involving keyboard keys, mouse movements, clicks, holds, releases, and other interactions.</p>
<pre><code>Actions actions = new Actions(driver);</code></pre>
<hr>
<h2>4. Keys Class</h2>
<p>The <code>Keys</code> class contains constants representing keyboard keys that can be used with Selenium keyboard interactions.</p>
<pre><code>import org.openqa.selenium.Keys;</code></pre>
<p>Examples include <code>Keys.ENTER</code>, <code>Keys.TAB</code>, <code>Keys.ESCAPE</code>, <code>Keys.SHIFT</code>, <code>Keys.CONTROL</code>, <code>Keys.ALT</code>, and arrow keys.</p>
<hr>
<h2>5. Required Imports</h2>
<pre><code>import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.Keys;</code></pre>
<hr>
<h2>6. Basic Keyboard Action Syntax</h2>
<pre><code>Actions actions = new Actions(driver);
actions.sendKeys(Keys.ENTER).perform();</code></pre>
<p>The general workflow is:</p>
<pre><code>Locate Element
↓
Create Actions Object
↓
Choose Keyboard Key
↓
Build Keyboard Action
↓
Perform Action
↓
Validate Result</code></pre>
<hr>
<h2>7. Sending Text Using sendKeys()</h2>
<p>The <code>sendKeys()</code> method can be used to send text or keyboard keys to the current active element.</p>
<pre><code>new Actions(driver)
.sendKeys("Selenium Automation")
.perform();</code></pre>
<hr>
<h2>8. Sending Keys to a WebElement</h2>
<pre><code>WebElement searchBox = driver.findElement(
By.id("search")
);
new Actions(driver)
.click(searchBox)
.sendKeys("Selenium")
.perform();</code></pre>
<hr>
<h2>9. Using WebElement.sendKeys()</h2>
<p>For simple text input, <code>WebElement.sendKeys()</code> is often sufficient. The Actions API becomes particularly useful for advanced keyboard sequences and combinations.</p>
<pre><code>WebElement username = driver.findElement(
By.id("username")
);
username.sendKeys("testuser");</code></pre>
<hr>
<h2>10. Actions sendKeys() vs WebElement sendKeys()</h2>
<table border="1" cellpadding="8" cellspacing="0">
<tr><th>Feature</th><th>WebElement.sendKeys()</th><th>Actions.sendKeys()</th></tr>
<tr><td>Simple text input</td><td>Yes</td><td>Yes</td></tr>
<tr><td>Keyboard shortcuts</td><td>Limited</td><td>Yes</td></tr>
<tr><td>Active element interaction</td><td>Element-specific</td><td>Yes</td></tr>
<tr><td>Key combinations</td><td>Possible for element input</td><td>Better suited</td></tr>
<tr><td>Advanced sequences</td><td>Limited</td><td>Yes</td></tr>
</table>
<hr>
<h2>11. Pressing Enter Key</h2>
<p>The Enter key is commonly used to submit forms, perform searches, confirm selections, or activate controls.</p>
<pre><code>WebElement searchBox = driver.findElement(
By.id("search")
);
new Actions(driver)
.click(searchBox)
.sendKeys("Selenium")
.sendKeys(Keys.ENTER)
.perform();</code></pre>
<hr>
<h2>12. Pressing Tab Key</h2>
<p>The Tab key moves focus to the next focusable element.</p>
<pre><code>new Actions(driver)
.sendKeys(Keys.TAB)
.perform();</code></pre>
<hr>
<h2>13. Pressing Shift + Tab</h2>
<p>Shift + Tab usually moves focus to the previous focusable element.</p>
<pre><code>new Actions(driver)
.keyDown(Keys.SHIFT)
.sendKeys(Keys.TAB)
.keyUp(Keys.SHIFT)
.perform();</code></pre>
<hr>
<h2>14. Pressing Escape Key</h2>
<p>The Escape key is frequently used to close menus, dialogs, popups, dropdowns, and modal interfaces.</p>
<pre><code>new Actions(driver)
.sendKeys(Keys.ESCAPE)
.perform();</code></pre>
<hr>
<h2>15. Pressing Space Key</h2>
<p>The Space key can be used to activate focused controls such as checkboxes, buttons, or custom interactive elements.</p>
<pre><code>new Actions(driver)
.sendKeys(Keys.SPACE)
.perform();</code></pre>
<hr>
<h2>16. Pressing Arrow Keys</h2>
<p>Arrow keys are useful for dropdowns, menus, sliders, calendars, custom controls, and keyboard navigation.</p>
<pre><code>new Actions(driver)
.sendKeys(Keys.ARROW_DOWN)
.sendKeys(Keys.ARROW_DOWN)
.sendKeys(Keys.ENTER)
.perform();</code></pre>
<hr>
<h2>17. Right Arrow Key</h2>
<pre><code>new Actions(driver)
.sendKeys(Keys.ARROW_RIGHT)
.perform();</code></pre>
<hr>
<h2>18. Left Arrow Key</h2>
<pre><code>new Actions(driver)
.sendKeys(Keys.ARROW_LEFT)
.perform();</code></pre>
<hr>
<h2>19. Up Arrow Key</h2>
<pre><code>new Actions(driver)
.sendKeys(Keys.ARROW_UP)
.perform();</code></pre>
<hr>
<h2>20. Down Arrow Key</h2>
<pre><code>new Actions(driver)
.sendKeys(Keys.ARROW_DOWN)
.perform();</code></pre>
<hr>
<h2>21. Using Backspace</h2>
<p>The Backspace key can be used to remove characters from an input field when the cursor is positioned appropriately.</p>
<pre><code>new Actions(driver)
.sendKeys(Keys.BACK_SPACE)
.perform();</code></pre>
<hr>
<h2>22. Using Delete Key</h2>
<pre><code>new Actions(driver)
.sendKeys(Keys.DELETE)
.perform();</code></pre>
<hr>
<h2>23. Using Home Key</h2>
<p>The Home key can move the cursor to the beginning of a line or navigate to the beginning of a list depending on the application.</p>
<pre><code>new Actions(driver)
.sendKeys(Keys.HOME)
.perform();</code></pre>
<hr>
<h2>24. Using End Key</h2>
<pre><code>new Actions(driver)
.sendKeys(Keys.END)
.perform();</code></pre>
<hr>
<h2>25. Using Page Up</h2>
<pre><code>new Actions(driver)
.sendKeys(Keys.PAGE_UP)
.perform();</code></pre>
<hr>
<h2>26. Using Page Down</h2>
<pre><code>new Actions(driver)
.sendKeys(Keys.PAGE_DOWN)
.perform();</code></pre>
<hr>
<h2>27. Using Control Key</h2>
<p>The Control key is commonly used for keyboard shortcuts such as Ctrl+A, Ctrl+C, Ctrl+V, and Ctrl+S.</p>
<pre><code>new Actions(driver)
.keyDown(Keys.CONTROL)
.sendKeys("a")
.keyUp(Keys.CONTROL)
.perform();</code></pre>
<hr>
<h2>28. Using Shift Key</h2>
<p>The Shift key can be used to create uppercase characters, select text, and execute Shift-based shortcuts.</p>
<pre><code>new Actions(driver)
.keyDown(Keys.SHIFT)
.sendKeys("selenium")
.keyUp(Keys.SHIFT)
.perform();</code></pre>
<hr>
<h2>29. Using Alt Key</h2>
<pre><code>new Actions(driver)
.keyDown(Keys.ALT)
.sendKeys("a")
.keyUp(Keys.ALT)
.perform();</code></pre>
<hr>
<h2>30. Using Meta Key</h2>
<p>The Meta key can be relevant to platform-specific shortcuts, particularly on macOS.</p>
<pre><code>new Actions(driver)
.keyDown(Keys.META)
.sendKeys("a")
.keyUp(Keys.META)
.perform();</code></pre>
<hr>
<h2>31. Understanding keyDown()</h2>
<p>The <code>keyDown()</code> method presses a modifier key and keeps it active until it is released.</p>
<pre><code>new Actions(driver)
.keyDown(Keys.CONTROL)
.sendKeys("a")
.perform();</code></pre>
<p>When a modifier is intentionally held, it should normally be released using <code>keyUp()</code>.</p>
<hr>
<h2>32. Understanding keyUp()</h2>
<p>The <code>keyUp()</code> method releases a previously pressed modifier key.</p>
<pre><code>new Actions(driver)
.keyDown(Keys.CONTROL)
.sendKeys("a")
.keyUp(Keys.CONTROL)
.perform();</code></pre>
<hr>
<h2>33. Ctrl + A Select All</h2>
<p>Ctrl+A is commonly used to select all text inside an input field.</p>
<pre><code>WebElement input = driver.findElement(
By.id("username")
);
new Actions(driver)
.click(input)
.keyDown(Keys.CONTROL)
.sendKeys("a")
.keyUp(Keys.CONTROL)
.perform();</code></pre>
<hr>
<h2>34. Ctrl + C Copy</h2>
<pre><code>new Actions(driver)
.keyDown(Keys.CONTROL)
.sendKeys("c")
.keyUp(Keys.CONTROL)
.perform();</code></pre>
<hr>
<h2>35. Ctrl + V Paste</h2>
<pre><code>new Actions(driver)
.keyDown(Keys.CONTROL)
.sendKeys("v")
.keyUp(Keys.CONTROL)
.perform();</code></pre>
<hr>
<h2>36. Ctrl + X Cut</h2>
<pre><code>new Actions(driver)
.keyDown(Keys.CONTROL)
.sendKeys("x")
.keyUp(Keys.CONTROL)
.perform();</code></pre>
<hr>
<h2>37. Ctrl + Z Undo</h2>
<pre><code>new Actions(driver)
.keyDown(Keys.CONTROL)
.sendKeys("z")
.keyUp(Keys.CONTROL)
.perform();</code></pre>
<hr>
<h2>38. Ctrl + Y Redo</h2>
<pre><code>new Actions(driver)
.keyDown(Keys.CONTROL)
.sendKeys("y")
.keyUp(Keys.CONTROL)
.perform();</code></pre>
<hr>
<h2>39. Ctrl + S Save Shortcut</h2>
<p>Applications with custom save shortcuts can be tested using keyboard combinations.</p>
<pre><code>new Actions(driver)
.keyDown(Keys.CONTROL)
.sendKeys("s")
.keyUp(Keys.CONTROL)
.perform();</code></pre>
<hr>
<h2>40. Ctrl + F Search Shortcut</h2>
<pre><code>new Actions(driver)
.keyDown(Keys.CONTROL)
.sendKeys("f")
.keyUp(Keys.CONTROL)
.perform();</code></pre>
<hr>
<h2>41. Ctrl + A and Replace Text</h2>
<p>A common automation workflow is selecting existing text and replacing it with new content.</p>
<pre><code>WebElement input = driver.findElement(
By.id("email")
);
new Actions(driver)
.click(input)
.keyDown(Keys.CONTROL)
.sendKeys("a")
.keyUp(Keys.CONTROL)
.sendKeys("[email protected]")
.perform();</code></pre>
<hr>
<h2>42. Selecting Text with Shift</h2>
<p>Shift combined with arrow keys can select text in applications that support standard keyboard selection behavior.</p>
<pre><code>new Actions(driver)
.keyDown(Keys.SHIFT)
.sendKeys(Keys.ARROW_RIGHT)
.sendKeys(Keys.ARROW_RIGHT)
.sendKeys(Keys.ARROW_RIGHT)
.keyUp(Keys.SHIFT)
.perform();</code></pre>
<hr>
<h2>43. Keyboard Navigation Between Form Fields</h2>
<p>Keyboard navigation can be used to verify that users can move through a form using the Tab key.</p>
<pre><code>new Actions(driver)
.sendKeys("John")
.sendKeys(Keys.TAB)
.sendKeys("[email protected]")
.sendKeys(Keys.TAB)
.sendKeys("1234567890")
.perform();</code></pre>
<hr>
<h2>44. Form Submission Using Enter</h2>
<pre><code>WebElement username = driver.findElement(
By.id("username")
);
username.sendKeys("testuser");
new Actions(driver)
.sendKeys(Keys.ENTER)
.perform();</code></pre>
<hr>
<h2>45. Keyboard Action on Search Box</h2>
<pre><code>WebElement search = driver.findElement(
By.name("q")
);
new Actions(driver)
.click(search)
.sendKeys("Selenium WebDriver")
.sendKeys(Keys.ENTER)
.perform();</code></pre>
<hr>
<h2>46. Keyboard Actions on Login Form</h2>
<pre><code>WebElement username = driver.findElement(
By.id("username")
);
WebElement password = driver.findElement(
By.id("password")
);
new Actions(driver)
.click(username)
.sendKeys("testuser")
.sendKeys(Keys.TAB)
.sendKeys("Password123")
.sendKeys(Keys.ENTER)
.perform();</code></pre>
<hr>
<h2>47. Keyboard Actions with Dropdown</h2>
<p>Custom dropdowns can sometimes be navigated using arrow keys and Enter.</p>
<pre><code>WebElement dropdown = driver.findElement(
By.id("country")
);
new Actions(driver)
.click(dropdown)
.sendKeys(Keys.ARROW_DOWN)
.sendKeys(Keys.ARROW_DOWN)
.sendKeys(Keys.ENTER)
.perform();</code></pre>
<hr>
<h2>48. Keyboard Actions with Autocomplete</h2>
<p>Autocomplete fields often require typing text and selecting a suggestion using the keyboard.</p>
<pre><code>WebElement city = driver.findElement(
By.id("city")
);
new Actions(driver)
.click(city)
.sendKeys("Mumbai")
.pause(Duration.ofMillis(500))
.sendKeys(Keys.ARROW_DOWN)
.sendKeys(Keys.ENTER)
.perform();</code></pre>
<hr>
<h2>49. Keyboard Actions with Modal Dialog</h2>
<p>Escape can be used to close a custom modal or dialog when the application supports keyboard dismissal.</p>
<pre><code>new Actions(driver)
.sendKeys(Keys.ESCAPE)
.perform();</code></pre>
<hr>
<h2>50. Keyboard Actions with Menus</h2>
<p>Keyboard actions can be used to navigate custom menus using arrow keys and Enter.</p>
<pre><code>new Actions(driver)
.sendKeys(Keys.ARROW_DOWN)
.sendKeys(Keys.ARROW_DOWN)
.sendKeys(Keys.ARROW_RIGHT)
.sendKeys(Keys.ENTER)
.perform();</code></pre>
<hr>
<h2>51. Keyboard Actions with Checkboxes</h2>
<p>A focused checkbox can often be toggled using the Space key.</p>
<pre><code>WebElement checkbox = driver.findElement(
By.id("terms")
);
new Actions(driver)
.click(checkbox)
.sendKeys(Keys.SPACE)
.perform();</code></pre>
<hr>
<h2>52. Keyboard Actions with Radio Buttons</h2>
<pre><code>WebElement radio = driver.findElement(
By.id("male")
);
new Actions(driver)
.click(radio)
.sendKeys(Keys.SPACE)
.perform();</code></pre>
<hr>
<h2>53. Keyboard Actions with Buttons</h2>
<p>When a button has keyboard focus, Enter or Space may activate it depending on the control.</p>
<pre><code>WebElement button = driver.findElement(
By.id("submit")
);
new Actions(driver)
.click(button)
.sendKeys(Keys.ENTER)
.perform();</code></pre>
<hr>
<h2>54. Keyboard Actions with Text Areas</h2>
<pre><code>WebElement textarea = driver.findElement(
By.id("comments")
);
new Actions(driver)
.click(textarea)
.sendKeys("This is a Selenium keyboard test.")
.perform();</code></pre>
<hr>
<h2>55. Keyboard Actions with Multiline Text</h2>
<p>For controls that interpret Enter as a newline, keyboard actions can create multiline input.</p>
<pre><code>new Actions(driver)
.sendKeys("First line")
.sendKeys(Keys.ENTER)
.sendKeys("Second line")
.perform();</code></pre>
<hr>
<h2>56. Keyboard Actions with Contenteditable</h2>
<p>Rich text editors often use <code>contenteditable</code> elements and can require Actions-based keyboard input.</p>
<pre><code>WebElement editor = driver.findElement(
By.cssSelector("[contenteditable='true']")
);
new Actions(driver)
.click(editor)
.sendKeys("Selenium keyboard automation")
.perform();</code></pre>
<hr>
<h2>57. Keyboard Actions for Text Selection</h2>
<pre><code>WebElement input = driver.findElement(
By.id("message")
);
new Actions(driver)
.click(input)
.keyDown(Keys.CONTROL)
.sendKeys("a")
.keyUp(Keys.CONTROL)
.perform();</code></pre>
<hr>
<h2>58. Keyboard Actions for Clearing Text</h2>
<p>A common keyboard approach is selecting all text and pressing Backspace.</p>
<pre><code>new Actions(driver)
.keyDown(Keys.CONTROL)
.sendKeys("a")
.keyUp(Keys.CONTROL)
.sendKeys(Keys.BACK_SPACE)
.perform();</code></pre>
<hr>
<h2>59. clear() vs Keyboard Clearing</h2>
<table border="1" cellpadding="8" cellspacing="0">
<tr><th>Aspect</th><th>clear()</th><th>Keyboard Method</th></tr>
<tr><td>Simple input clearing</td><td>Yes</td><td>Yes</td></tr>
<tr><td>Simulates keyboard behavior</td><td>No</td><td>Yes</td></tr>
<tr><td>Keyboard event testing</td><td>Limited</td><td>Better suited</td></tr>
<tr><td>Shortcut support</td><td>No</td><td>Yes</td></tr>
</table>
<hr>
<h2>60. Keyboard Actions with Explicit Wait</h2>
<p>Dynamic elements should be synchronized before keyboard actions are performed.</p>
<pre><code>WebDriverWait wait =
new WebDriverWait(driver, Duration.ofSeconds(10));
WebElement search = wait.until(
ExpectedConditions.elementToBeClickable(
By.id("search")
)
);
new Actions(driver)
.click(search)
.sendKeys("Selenium")
.sendKeys(Keys.ENTER)
.perform();</code></pre>
<hr>
<h2>61. Required Wait Imports</h2>
<pre><code>import java.time.Duration;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;</code></pre>
<hr>
<h2>62. Keyboard Actions with Dynamic Elements</h2>
<pre><code>WebDriverWait wait =
new WebDriverWait(driver, Duration.ofSeconds(10));
WebElement input = wait.until(
ExpectedConditions.visibilityOfElementLocated(
By.cssSelector(".dynamic-input")
)
);
new Actions(driver)
.click(input)
.sendKeys("Dynamic Element")
.perform();</code></pre>
<hr>
<h2>63. Keyboard Actions with iframe</h2>
<p>If the target element is inside an iframe, Selenium must switch to that frame before performing keyboard actions on the element.</p>
<pre><code>driver.switchTo().frame("loginFrame");
WebElement username = driver.findElement(
By.id("username")
);
new Actions(driver)
.click(username)
.sendKeys("testuser")
.perform();
driver.switchTo().defaultContent();</code></pre>
<hr>
<h2>64. Keyboard Actions in Nested Frames</h2>
<pre><code>driver.switchTo().frame("outerFrame");
driver.switchTo().frame("innerFrame");
WebElement input = driver.findElement(
By.id("input")
);
new Actions(driver)
.click(input)
.sendKeys("Test Data")
.perform();
driver.switchTo().defaultContent();</code></pre>
<hr>
<h2>65. Keyboard Actions with Browser Windows</h2>
<p>Keyboard actions operate within the currently active browser window or tab. Selenium must switch to the required window before interacting with its elements.</p>
<pre><code>driver.switchTo().window(windowHandle);
new Actions(driver)
.sendKeys(Keys.TAB)
.perform();</code></pre>
<hr>
<h2>66. Keyboard Actions with Alerts</h2>
<p>JavaScript alerts are handled through Selenium's Alert API rather than normal WebElement keyboard actions.</p>
<pre><code>Alert alert = driver.switchTo().alert();
alert.sendKeys("Test Input");
alert.accept();</code></pre>
<hr>
<h2>67. Alert Import</h2>
<pre><code>import org.openqa.selenium.Alert;</code></pre>
<hr>
<h2>68. Keyboard Actions and Browser Shortcuts</h2>
<p>Some browser-level shortcuts can behave differently across browsers, operating systems, browser configurations, or security restrictions. Application-level keyboard interactions should generally be the focus of automated tests.</p>
<hr>
<h2>69. Keyboard Actions on Focused Elements</h2>
<p>When <code>Actions.sendKeys()</code> is used without explicitly clicking an element, the active element or current browser context receives the keyboard input.</p>
<pre><code>new Actions(driver)
.sendKeys("Hello")
.perform();</code></pre>
<hr>
<h2>70. Why Focus Matters?</h2>
<p>Keyboard events depend heavily on focus. If the wrong element is focused, the keyboard action may be sent to an unexpected control.</p>
<ul>
<li>Click the required element when appropriate.</li>
<li>Use Tab navigation when testing keyboard workflows.</li>
<li>Verify the active element for complex applications.</li>
<li>Avoid assuming focus is always correct.</li>
</ul>
<hr>
<h2>71. Checking Active Element</h2>
<p>JavaScript can be used to inspect which element currently has focus.</p>
<pre><code>JavascriptExecutor js =
(JavascriptExecutor) driver;
WebElement activeElement =
(WebElement) js.executeScript(
"return document.activeElement;"
);
System.out.println(
activeElement.getAttribute("id")
);</code></pre>
<hr>
<h2>72. Keyboard Navigation Test</h2>
<p>A keyboard navigation test can verify whether focus moves through a form in the expected order.</p>
<pre><code>WebElement username = driver.findElement(
By.id("username")
);
new Actions(driver)
.click(username)
.sendKeys("testuser")
.sendKeys(Keys.TAB)
.sendKeys("password")
.sendKeys(Keys.TAB)
.sendKeys(Keys.ENTER)
.perform();</code></pre>
<hr>
<h2>73. Keyboard Actions for Accessibility Testing</h2>
<p>Keyboard automation can help verify whether important application functions are reachable and usable through keyboard interaction.</p>
<ul>
<li>Tab navigation.</li>
<li>Shift + Tab navigation.</li>
<li>Enter activation.</li>
<li>Space activation.</li>
<li>Escape behavior.</li>
<li>Arrow-key navigation.</li>
<li>Keyboard-accessible menus.</li>
<li>Keyboard-accessible dialogs.</li>
</ul>
<hr>
<h2>74. Testing Tab Order</h2>
<pre><code>new Actions(driver)
.click(firstField)
.sendKeys(Keys.TAB)
.sendKeys(Keys.TAB)
.sendKeys(Keys.TAB)
.perform();</code></pre>
<hr>
<h2>75. Keyboard Actions for Search Suggestions</h2>
<pre><code>WebElement search = driver.findElement(
By.id("search")
);
new Actions(driver)
.click(search)
.sendKeys("Selenium")
.pause(Duration.ofMillis(500))
.sendKeys(Keys.ARROW_DOWN)
.sendKeys(Keys.ENTER)
.perform();</code></pre>
<hr>
<h2>76. Keyboard Actions for Calendar Navigation</h2>
<p>Calendar widgets may use arrow keys to move between dates and Enter to select a date.</p>
<pre><code>WebElement calendar = driver.findElement(
By.id("calendar")
);
new Actions(driver)
.click(calendar)
.sendKeys(Keys.ARROW_RIGHT)
.sendKeys(Keys.ARROW_RIGHT)
.sendKeys(Keys.ENTER)
.perform();</code></pre>
<hr>
<h2>77. Keyboard Actions for Sliders</h2>
<p>Accessible sliders may be controlled using arrow keys after the slider handle receives focus.</p>
<pre><code>WebElement slider = driver.findElement(
By.cssSelector(".slider")
);
new Actions(driver)
.click(slider)
.sendKeys(Keys.ARROW_RIGHT)
.sendKeys(Keys.ARROW_RIGHT)
.sendKeys(Keys.ARROW_RIGHT)
.perform();</code></pre>
<hr>
<h2>78. Keyboard Actions for Menus</h2>
<pre><code>WebElement menu = driver.findElement(
By.id("menu")
);
new Actions(driver)
.click(menu)
.sendKeys(Keys.ARROW_DOWN)
.sendKeys(Keys.ARROW_DOWN)
.sendKeys(Keys.ENTER)
.perform();</code></pre>
<hr>
<h2>79. Keyboard Actions for Autocomplete Fields</h2>
<pre><code>WebElement input = driver.findElement(
By.id("location")
);
new Actions(driver)
.click(input)
.sendKeys("Mumbai")
.pause(Duration.ofMillis(500))
.sendKeys(Keys.ARROW_DOWN)
.sendKeys(Keys.ENTER)
.perform();</code></pre>
<hr>
<h2>80. Keyboard Actions for Rich Text Editors</h2>
<p>Rich text editors may support keyboard shortcuts for formatting, selection, indentation, and navigation.</p>
<pre><code>WebElement editor = driver.findElement(
By.cssSelector("[contenteditable='true']")
);
new Actions(driver)
.click(editor)
.sendKeys("Important Text")
.keyDown(Keys.CONTROL)
.sendKeys("a")
.keyUp(Keys.CONTROL)
.perform();</code></pre>
<hr>
<h2>81. Keyboard Actions with Pause</h2>
<p>The <code>pause()</code> method can introduce a short delay inside an Actions sequence when a specific application interaction requires it.</p>
<pre><code>new Actions(driver)
.click(searchBox)
.sendKeys("Selenium")
.pause(Duration.ofMillis(500))
.sendKeys(Keys.ENTER)
.perform();</code></pre>
<hr>
<h2>82. Why Use Pause Carefully?</h2>
<p>A fixed pause should not replace proper synchronization. Explicit waits are generally more appropriate when the application exposes a condition that can be observed.</p>
<hr>
<h2>83. Keyboard Actions and Thread.sleep()</h2>
<p>Using arbitrary delays can make tests slower and less reliable.</p>
<pre><code>Thread.sleep(3000);
new Actions(driver)
.sendKeys(Keys.ENTER)
.perform();</code></pre>
<p>Prefer explicit waits when waiting for a known UI state.</p>
<hr>
<h2>84. Keyboard Actions with Assertions</h2>
<p>After a keyboard interaction, the test should verify the resulting application state.</p>
<pre><code>new Actions(driver)
.click(searchBox)
.sendKeys("Selenium")
.sendKeys(Keys.ENTER)
.perform();
WebElement result = new WebDriverWait(
driver,
Duration.ofSeconds(10)
).until(
ExpectedConditions.visibilityOfElementLocated(
By.id("results")
)
);
Assert.assertTrue(
result.isDisplayed(),
"Search results were not displayed"
);</code></pre>
<hr>
<h2>85. Keyboard Actions with TestNG</h2>
<pre><code>@Test
public void verifySearchUsingKeyboard() {
WebElement search = driver.findElement(
By.id("search")
);
new Actions(driver)
.click(search)
.sendKeys("Selenium")
.sendKeys(Keys.ENTER)
.perform();
Assert.assertTrue(
driver.findElement(By.id("results"))
.isDisplayed()
);
}</code></pre>
<hr>
<h2>86. TestNG Imports</h2>
<pre><code>import org.testng.Assert;
import org.testng.annotations.Test;</code></pre>
<hr>
<h2>87. Keyboard Actions in Page Object Model</h2>
<p>Keyboard interaction logic can be placed inside page objects so that test classes remain simple and readable.</p>
<pre><code>public void searchUsingKeyboard(String text) {
WebElement search = driver.findElement(
By.id("search")
);
new Actions(driver)
.click(search)
.sendKeys(text)
.sendKeys(Keys.ENTER)
.perform();
}</code></pre>
<hr>
<h2>88. Page Object Example</h2>
<pre><code>public class SearchPage {
private WebDriver driver;
private By searchBox = By.id("search");
private By results = By.id("results");
public SearchPage(WebDriver driver) {
this.driver = driver;
}
public void search(String text) {
WebElement search =
driver.findElement(searchBox);
new Actions(driver)
.click(search)
.sendKeys(text)
.sendKeys(Keys.ENTER)
.perform();
}
public boolean isResultDisplayed() {
return driver.findElement(results)
.isDisplayed();
}
}</code></pre>
<hr>
<h2>89. Calling Page Object Method</h2>
<pre><code>@Test
public void verifySearch() {
SearchPage page =
new SearchPage(driver);
page.search("Selenium");
Assert.assertTrue(
page.isResultDisplayed()
);
}</code></pre>
<hr>
<h2>90. Reusable Keyboard Utility</h2>
<pre><code>public class KeyboardUtils {
private WebDriver driver;
public KeyboardUtils(WebDriver driver) {
this.driver = driver;
}
public void pressEnter() {
new Actions(driver)
.sendKeys(Keys.ENTER)
.perform();
}
public void pressEscape() {
new Actions(driver)
.sendKeys(Keys.ESCAPE)
.perform();
}
public void pressTab() {
new Actions(driver)
.sendKeys(Keys.TAB)
.perform();
}
}</code></pre>
<hr>
<h2>91. Reusable Shortcut Utility</h2>
<pre><code>public void ctrlA() {
new Actions(driver)
.keyDown(Keys.CONTROL)
.sendKeys("a")
.keyUp(Keys.CONTROL)
.perform();
}
public void ctrlC() {
new Actions(driver)
.keyDown(Keys.CONTROL)
.sendKeys("c")
.keyUp(Keys.CONTROL)
.perform();
}
public void ctrlV() {
new Actions(driver)
.keyDown(Keys.CONTROL)
.sendKeys("v")
.keyUp(Keys.CONTROL)
.perform();
}</code></pre>
<hr>
<h2>92. Reusable Keyboard Navigation Utility</h2>
<pre><code>public void pressArrowDown(int count) {
Actions actions = new Actions(driver);
for (int i = 0; i < count; i++) {
actions.sendKeys(Keys.ARROW_DOWN);
}
actions.perform();
}</code></pre>
<hr>
<h2>93. Platform-Specific Modifier Keys</h2>
<p>Keyboard shortcuts can differ between operating systems. For example, Control is commonly used on Windows/Linux, while Meta is commonly used for many equivalent shortcuts on macOS.</p>
<pre><code>Keys modifier = Keys.CONTROL;
new Actions(driver)
.keyDown(modifier)
.sendKeys("a")
.keyUp(modifier)
.perform();</code></pre>
<hr>
<h2>94. Keyboard Actions and Browser Compatibility</h2>
<p>Keyboard interactions should be validated on the browsers supported by the application because browser behavior and application event handling can vary.</p>
<table border="1" cellpadding="8" cellspacing="0">
<tr><th>Browser</th><th>Keyboard Validation</th></tr>
<tr><td>Chrome</td><td>Keyboard navigation and shortcuts</td></tr>
<tr><td>Firefox</td><td>Keyboard navigation and shortcuts</td></tr>
<tr><td>Edge</td><td>Keyboard navigation and shortcuts</td></tr>
</table>
<hr>
<h2>95. Keyboard Actions and Responsive Applications</h2>
<p>Keyboard interactions are generally less dependent on screen coordinates than mouse interactions, but focus behavior can still change depending on responsive layouts and application state.</p>
<hr>
<h2>96. Keyboard Actions and Dynamic UI</h2>
<p>Modern JavaScript applications can dynamically replace elements. When this occurs, locate the current element before performing the keyboard action.</p>
<pre><code>WebDriverWait wait =
new WebDriverWait(driver, Duration.ofSeconds(10));
WebElement input = wait.until(
ExpectedConditions.elementToBeClickable(
By.id("dynamicInput")
)
);
new Actions(driver)
.click(input)
.sendKeys("Test")
.perform();</code></pre>
<hr>
<h2>97. Common Keyboard Exceptions</h2>
<ul>
<li><code>NoSuchElementException</code></li>
<li><code>StaleElementReferenceException</code></li>
<li><code>ElementNotInteractableException</code></li>
<li><code>ElementClickInterceptedException</code></li>
<li><code>MoveTargetOutOfBoundsException</code></li>
</ul>
<hr>
<h2>98. ElementNotInteractableException</h2>
<p>This can occur when the target element is not currently available for interaction.</p>
<ul>
<li>Element is hidden.</li>
<li>Element is disabled.</li>
<li>Element is outside the required application state.</li>
<li>Another element is blocking it.</li>
<li>The page has not completed the required loading.</li>
</ul>
<hr>
<h2>99. StaleElementReferenceException</h2>
<p>A stale element can occur when the DOM changes after an element was located. Re-locate the current element before performing the keyboard action.</p>
<pre><code>WebDriverWait wait =
new WebDriverWait(driver, Duration.ofSeconds(10));
WebElement input = wait.until(
ExpectedConditions.refreshed(
ExpectedConditions.elementToBeClickable(
By.id("input")
)
)
);
new Actions(driver)
.click(input)
.sendKeys("Test")
.perform();</code></pre>
<hr>
<h2>100. Keyboard Actions Troubleshooting</h2>
<p>When a keyboard interaction fails, check the following areas:</p>
<ul>
<li>Verify the element locator.</li>
<li>Verify that the element is visible.</li>
<li>Verify that the element is enabled.</li>
<li>Check whether the correct iframe is selected.</li>
<li>Check whether the element has keyboard focus.</li>
<li>Verify that no overlay is blocking the element.</li>
<li>Wait for dynamic content when required.</li>
<li>Confirm the correct modifier key for the operating system.</li>
<li>Validate the application result.</li>
</ul>
<hr>
<h2>101. Keyboard Actions Best Practices</h2>
<ul>
<li>Use the <code>Actions</code> class for advanced keyboard sequences.</li>
<li>Use <code>WebElement.sendKeys()</code> for simple text input when appropriate.</li>
<li>Use stable locators.</li>
<li>Ensure the correct element has focus.</li>
<li>Use explicit waits for dynamic elements.</li>
<li>Release modifier keys with <code>keyUp()</code>.</li>
<li>Avoid unnecessary hard-coded delays.</li>
<li>Validate the result after keyboard interaction.</li>
<li>Keep reusable keyboard operations inside utilities.</li>
<li>Keep page-specific locators inside page objects.</li>
<li>Test keyboard workflows across supported browsers.</li>
<li>Include keyboard accessibility scenarios where relevant.</li>
</ul>
<hr>
<h2>102. Common Mistakes</h2>
<ul>
<li>Sending keys without verifying which element has focus.</li>
<li>Forgetting to release a modifier key.</li>
<li>Using incorrect platform-specific shortcuts.</li>
<li>Using <code>Thread.sleep()</code> unnecessarily.</li>
<li>Ignoring dynamic element changes.</li>
<li>Not switching into the correct iframe.</li>
<li>Assuming every custom component follows standard keyboard behavior.</li>
<li>Not validating the final UI state.</li>
<li>Duplicating keyboard action code across test classes.</li>
<li>Using keyboard shortcuts when a simpler element interaction is more appropriate.</li>
</ul>
<hr>
<h2>103. Keyboard Actions vs JavaScript</h2>
<table border="1" cellpadding="8" cellspacing="0">
<tr><th>Aspect</th><th>Keyboard Actions</th><th>JavaScript</th></tr>
<tr><td>Simulates user keyboard interaction</td><td>Yes</td><td>Not necessarily</td></tr>
<tr><td>Keyboard event testing</td><td>Suitable</td><td>Usually less suitable</td></tr>
<tr><td>Focus behavior</td><td>Can be tested</td><td>Can be manipulated directly</td></tr>
<tr><td>Realistic user interaction</td><td>Higher</td><td>Depends on implementation</td></tr>
<tr><td>Application keyboard shortcuts</td><td>Suitable</td><td>Usually not preferred</td></tr>
</table>
<hr>
<h2>104. Keyboard Actions with Screenshots on Failure</h2>
<pre><code>try {
new Actions(driver)
.click(searchBox)
.sendKeys("Selenium")
.sendKeys(Keys.ENTER)
.perform();
} catch (Exception e) {
File screenshot =
((TakesScreenshot) driver)
.getScreenshotAs(OutputType.FILE);
System.out.println(
"Keyboard action failed: " + e.getMessage()
);
}</code></pre>
<hr>
<h2>105. Screenshot Imports</h2>
<pre><code>import java.io.File;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;</code></pre>
<hr>
<h2>106. Logging Keyboard Actions</h2>
<pre><code>System.out.println("Clicking search box");
new Actions(driver)
.click(searchBox)
.perform();
System.out.println("Entering search text");
new Actions(driver)
.sendKeys("Selenium")
.perform();
System.out.println("Pressing Enter");
new Actions(driver)
.sendKeys(Keys.ENTER)
.perform();</code></pre>
<hr>
<h2>107. Practical Login Keyboard Scenario</h2>
<p>Consider a login form where the tester wants to enter the username, move to the password field using Tab, and submit the form using Enter.</p>
<ol>
<li>Open the login page.</li>
<li>Locate the username field.</li>
<li>Click the username field.</li>
<li>Enter the username.</li>
<li>Press Tab.</li>
<li>Enter the password.</li>
<li>Press Enter.</li>
<li>Wait for the dashboard.</li>
<li>Validate successful login.</li>
</ol>
<hr>
<h2>108. Practical Login Example</h2>
<pre><code>WebDriverWait wait =
new WebDriverWait(driver, Duration.ofSeconds(10));
WebElement username = wait.until(
ExpectedConditions.elementToBeClickable(
By.id("username")
)
);
new Actions(driver)
.click(username)
.sendKeys("testuser")
.sendKeys(Keys.TAB)
.sendKeys("Password123")
.sendKeys(Keys.ENTER)
.perform();
WebElement dashboard = wait.until(
ExpectedConditions.visibilityOfElementLocated(
By.id("dashboard")
)
);
Assert.assertTrue(
dashboard.isDisplayed(),
"Dashboard was not displayed"
);</code></pre>
<hr>
<h2>109. Practical Search Scenario</h2>
<p>Automate a product search using only keyboard interaction after focusing the search field.</p>
<pre><code>WebElement search = driver.findElement(
By.id("productSearch")
);
new Actions(driver)
.click(search)
.sendKeys("Laptop")
.sendKeys(Keys.ENTER)
.perform();
WebElement results = new WebDriverWait(
driver,
Duration.ofSeconds(10)
).until(
ExpectedConditions.visibilityOfElementLocated(
By.id("searchResults")
)
);
Assert.assertTrue(results.isDisplayed());</code></pre>
<hr>
<h2>110. Practical Form Navigation Scenario</h2>
<pre><code>WebElement firstName = driver.findElement(
By.id("firstName")
);
new Actions(driver)
.click(firstName)
.sendKeys("John")
.sendKeys(Keys.TAB)
.sendKeys("Doe")
.sendKeys(Keys.TAB)
.sendKeys("[email protected]")
.sendKeys(Keys.TAB)
.sendKeys("1234567890")
.perform();</code></pre>
<hr>
<h2>111. Practical Dropdown Scenario</h2>
<pre><code>WebElement country = driver.findElement(
By.id("country")
);
new Actions(driver)
.click(country)
.sendKeys(Keys.ARROW_DOWN)
.sendKeys(Keys.ARROW_DOWN)
.sendKeys(Keys.ARROW_DOWN)
.sendKeys(Keys.ENTER)
.perform();</code></pre>
<hr>
<h2>112. Practical Keyboard Accessibility Scenario</h2>
<p>Test whether a user can navigate through important controls without relying on mouse clicks.</p>
<pre><code>new Actions(driver)
.sendKeys(Keys.TAB)
.sendKeys(Keys.TAB)
.sendKeys(Keys.TAB)
.sendKeys(Keys.ENTER)
.perform();</code></pre>
<hr>
<h2>113. Practical Mini Project</h2>
<p><strong>Project:</strong> Keyboard-Based Login and Search Automation</p>
<p>Create an automation flow where the user logs into a web application using keyboard navigation and then performs a search using the keyboard.</p>
<ol>
<li>Launch Chrome.</li>
<li>Open the application.</li>
<li>Wait for the username field.</li>
<li>Enter username.</li>
<li>Press Tab.</li>
<li>Enter password.</li>
<li>Press Enter.</li>
<li>Wait for the dashboard.</li>
<li>Locate the search field.</li>
<li>Enter the search keyword.</li>
<li>Press Enter.</li>
<li>Wait for search results.</li>
<li>Validate the result.</li>
<li>Capture a screenshot if the test fails.</li>
</ol>
<hr>
<h2>114. Complete Mini Project Example</h2>
<pre><code>@Test
public void verifyKeyboardLoginAndSearch() {
WebDriverWait wait =
new WebDriverWait(driver, Duration.ofSeconds(10));
WebElement username = wait.until(
ExpectedConditions.elementToBeClickable(
By.id("username")
)
);
new Actions(driver)
.click(username)
.sendKeys("testuser")
.sendKeys(Keys.TAB)
.sendKeys("Password123")
.sendKeys(Keys.ENTER)
.perform();
WebElement dashboard = wait.until(
ExpectedConditions.visibilityOfElementLocated(
By.id("dashboard")
)
);
Assert.assertTrue(
dashboard.isDisplayed(),
"Dashboard was not displayed"
);
WebElement search = wait.until(
ExpectedConditions.elementToBeClickable(
By.id("search")
)
);
new Actions(driver)
.click(search)
.sendKeys("Selenium")
.sendKeys(Keys.ENTER)
.perform();
WebElement results = wait.until(
ExpectedConditions.visibilityOfElementLocated(
By.id("results")
)
);
Assert.assertTrue(
results.isDisplayed(),
"Search results were not displayed"
);
}</code></pre>
<hr>
<h2>115. Sample Test Cases</h2>
<table border="1" cellpadding="8" cellspacing="0">
<tr><th>Test Case ID</th><th>Scenario</th><th>Expected Result</th></tr>
<tr><td>TC-KEY-001</td><td>Press Enter in search field</td><td>Search is submitted</td></tr>
<tr><td>TC-KEY-002</td><td>Navigate using Tab</td><td>Focus moves to the next control</td></tr>
<tr><td>TC-KEY-003</td><td>Use Shift + Tab</td><td>Focus moves to the previous control</td></tr>
<tr><td>TC-KEY-004</td><td>Use Escape on modal</td><td>Modal closes when supported</td></tr>
<tr><td>TC-KEY-005</td><td>Use Arrow keys in dropdown</td><td>Option navigation works</td></tr>
<tr><td>TC-KEY-006</td><td>Use Ctrl+A</td><td>Text is selected</td></tr>
<tr><td>TC-KEY-007</td><td>Use keyboard form navigation</td><td>Focus moves correctly</td></tr>
<tr><td>TC-KEY-008</td><td>Submit login with Enter</td><td>Login is submitted</td></tr>
<tr><td>TC-KEY-009</td><td>Use keyboard on accessible control</td><td>Control responds correctly</td></tr>
<tr><td>TC-KEY-010</td><td>Keyboard shortcut</td><td>Application performs expected shortcut action</td></tr>
</table>
<hr>
<h2>116. Keyboard Action Test Case Template</h2>
<pre><code>Test Case ID: TC-KEY-001
Title: Verify Keyboard Action
Precondition: Application is available
Steps:
1. Open the application
2. Locate the required element
3. Give focus to the element
4. Perform the required keyboard action
5. Continue the keyboard sequence
6. Validate the application response
Expected Result:
The application should respond correctly to
the specified keyboard interaction.</code></pre>
<hr>
<h2>117. Interview Question: What are Keyboard Actions in Selenium?</h2>
<p>Keyboard Actions are advanced keyboard interactions used to simulate keys, keyboard shortcuts, navigation, text selection, form submission, and other keyboard-based user interactions in Selenium WebDriver.</p>
<hr>
<h2>118. Interview Question: Which Class is Used for Keyboard Actions?</h2>
<p>The <code>org.openqa.selenium.interactions.Actions</code> class is commonly used for advanced keyboard interactions.</p>
<hr>
<h2>119. Interview Question: Which Class Represents Keyboard Keys?</h2>
<p>The <code>org.openqa.selenium.Keys</code> class provides constants representing special keyboard keys such as Enter, Tab, Shift, Control, Escape, and Arrow keys.</p>
<hr>
<h2>120. Interview Question: Difference Between keyDown() and keyUp()?</h2>
<p><code>keyDown()</code> presses and holds a modifier key, while <code>keyUp()</code> releases that modifier key.</p>
<pre><code>new Actions(driver)
.keyDown(Keys.CONTROL)
.sendKeys("a")
.keyUp(Keys.CONTROL)
.perform();</code></pre>
<hr>
<h2>121. Interview Question: How do You Press Enter?</h2>
<pre><code>new Actions(driver)
.sendKeys(Keys.ENTER)
.perform();</code></pre>
<hr>
<h2>122. Interview Question: How do You Press Tab?</h2>
<pre><code>new Actions(driver)
.sendKeys(Keys.TAB)
.perform();</code></pre>
<hr>
<h2>123. Interview Question: How do You Perform Ctrl+A?</h2>
<pre><code>new Actions(driver)
.keyDown(Keys.CONTROL)
.sendKeys("a")
.keyUp(Keys.CONTROL)
.perform();</code></pre>
<hr>
<h2>124. Interview Question: How do You Perform Copy and Paste?</h2>
<pre><code>new Actions(driver)
.keyDown(Keys.CONTROL)
.sendKeys("c")
.keyUp(Keys.CONTROL)
.keyDown(Keys.CONTROL)
.sendKeys("v")
.keyUp(Keys.CONTROL)
.perform();</code></pre>
<hr>
<h2>125. Interview Question: Why is Focus Important?</h2>
<p>Keyboard events are delivered according to the active focus context. If the wrong element is focused, the keyboard action may be applied to the wrong control.</p>
<hr>
<h2>126. Interview Question: Can Actions Perform Keyboard and Mouse Actions Together?</h2>
<p>Yes. The <code>Actions</code> class can combine mouse and keyboard operations into a single action sequence.</p>
<pre><code>new Actions(driver)
.moveToElement(element)
.click()
.keyDown(Keys.CONTROL)
.sendKeys("a")
.keyUp(Keys.CONTROL)
.sendKeys("New Text")
.perform();</code></pre>
<hr>
<h2>127. Interview Question: What is perform()?</h2>
<p>The <code>perform()</code> method executes the built Actions sequence.</p>
<pre><code>new Actions(driver)
.sendKeys(Keys.ENTER)
.perform();</code></pre>
<hr>
<h2>128. Quick Revision</h2>
<ul>
<li>Keyboard Actions automate keyboard-based browser interactions.</li>
<li>The Selenium <code>Actions</code> class supports advanced keyboard sequences.</li>
<li>The <code>Keys</code> class provides keyboard key constants.</li>
<li>Use <code>sendKeys()</code> to send text or special keys.</li>
<li>Use <code>keyDown()</code> to press and hold a modifier.</li>
<li>Use <code>keyUp()</code> to release a modifier.</li>
<li>Use <code>Keys.ENTER</code> for Enter.</li>
<li>Use <code>Keys.TAB</code> for Tab.</li>
<li>Use <code>Keys.ESCAPE</code> for Escape.</li>
<li>Use <code>Keys.ARROW_DOWN</code> and other arrow keys for navigation.</li>
<li>Use Control or Meta depending on the platform and application shortcut.</li>
<li>Use explicit waits for dynamic elements.</li>
<li>Verify focus before performing complex keyboard interactions.</li>
<li>Validate the final application state.</li>
</ul>
<hr>
<h2>129. Keyboard Actions Checklist</h2>
<ul>
<li>Required element identified.</li>
<li>Stable locator used.</li>
<li>Element is visible.</li>
<li>Element is interactable.</li>
<li>Correct iframe selected if required.</li>
<li>Correct element has focus.</li>
<li>Actions object created.</li>
<li>Required keyboard key selected.</li>
<li>Modifier key pressed where required.</li>
<li>Keyboard action performed.</li>
<li>Modifier key released.</li>
<li>Application response validated.</li>
<li>Explicit wait used for dynamic behavior.</li>
<li>Screenshot captured for important failures.</li>
<li>Reusable keyboard utility used where appropriate.</li>
</ul>
<hr>
<h2>130. Best Keyboard Automation Workflow</h2>
<pre><code>Launch Browser
↓
Open Application
↓
Locate Element
↓
Wait Until Ready
↓
Give Element Focus
↓
Create Actions Object
↓
Press Required Key
↓
Use Modifier if Required
↓
Release Modifier
↓
Perform Action
↓
Wait for UI Response
↓
Validate Result</code></pre>
<hr>
<h2>131. Conclusion</h2>
<p>Keyboard Actions are an important part of Selenium WebDriver automation because many modern web applications depend on keyboard navigation, shortcuts, form submission, text editing, dropdown navigation, dialogs, menus, sliders, and accessibility features.</p>
<p>The Selenium <code>Actions</code> class provides powerful methods such as <code>sendKeys()</code>, <code>keyDown()</code>, <code>keyUp()</code>, <code>click()</code>, and other interaction methods that can be combined to create realistic keyboard workflows.</p>
<p>Reliable keyboard automation should use stable locators, correct focus management, explicit waits for dynamic elements, proper modifier-key handling, iframe switching when required, and assertions that verify the actual application result.</p>
<p><strong>Recommended Selenium Learning Resources:</strong></p>
<p><a href="https://www.justacademy.co/course-detail/selenium-training" target="_blank" rel="noopener noreferrer">Selenium Training Course</a> | <a href="https://www.justacademy.co/register-for-course-demo" target="_blank" rel="noopener noreferrer">Register for Course Demo</a></p>
</div>